package com.wawayaya.parentteacher.widget;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wawayaya.parentteacher.Constants;
import com.wawayaya.parentteacher.TeacherParentEvent;
import com.wawayaya.parentteacher.adapter.TpBookCoverAdapter;
import com.wawayaya.parentteacher.bean.BookShelf;
import com.wawayaya.ui.bookcover.BookCoverAdapter;
import com.wawayaya.util.event.ShelfEvent;


import java.util.ArrayList;

import cz.msebera.android.httpclient.extras.PRNGFixes;
import de.greenrobot.event.EventBus;
import wawayaya.kids_iread.R;

/**
 * Created by wang_qian on 2015/12/7.
 */
public class TpBookRack {
    private View    mView;
    private Context  mContext;
    private boolean   mIsZh;

    private LinearLayout mLlBookshelfBar;
    private ImageView mIvIcon;
    private TextView mTvName;
    private ImageButton mImgBtnMore;

    private RecyclerView recyclerView;
    private TpBookCoverAdapter bookCoverAdapter;

    private BookShelf  mBookShelfData;

    private int mLibClass;

    public TpBookRack(Context context, View v, BookShelf bookshelfdata, Boolean iszh, int libclass) {
        mView = v;
        mContext = context;
        mBookShelfData = bookshelfdata;
        mIsZh = iszh;
        mLibClass = libclass;
        initView();
    }

    private void initView() {
        mLlBookshelfBar = (LinearLayout)mView.findViewById(R.id.ll_bookshelf_bar);
        mLlBookshelfBar.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                TeacherParentEvent event;

                switch (mLibClass) {
                    case Constants.BOOK_LIB_CLASS_RECOMMEND:
                        event = new TeacherParentEvent(TeacherParentEvent.TYPE_SHOW_RECOMMEND_BOOKS, mBookShelfData.getBsId(), mBookShelfData.getBsNameEn());
                        EventBus.getDefault().post(event);
                        break;

                    case Constants.BOOK_LIB_CLASS_SERIES:
                        event = new TeacherParentEvent(TeacherParentEvent.TYPE_SHOW_SERIES_BOOKS, mBookShelfData.getBsId(), mBookShelfData.getBsNameEn());
                        EventBus.getDefault().post(event);
                        break;
                    case Constants.BOOK_LIB_CLASS_THEME:
                        event = new TeacherParentEvent(TeacherParentEvent.TYPE_SHOW_THEME_BOOKS, mBookShelfData.getBsId(), mBookShelfData.getBsNameEn());
                        EventBus.getDefault().post(event);
                        break;
                    case Constants.BOOK_LIB_CLASS_AGE:
                        event = new TeacherParentEvent(TeacherParentEvent.TYPE_SHOW_AGE_BOOKS, mBookShelfData.getBsId(), mBookShelfData.getBsNameEn());
                        EventBus.getDefault().post(event);
                        break;
                    case Constants.BOOK_LIB_CLASS_GRADE:
                        event = new TeacherParentEvent(TeacherParentEvent.TYPE_SHOW_GRADE_BOOKS, mBookShelfData.getBsId(), mBookShelfData.getBsNameEn());
                        EventBus.getDefault().post(event);
                        break;
                    case Constants.BOOK_LIB_CLASS_ENGLISH:
                        event = new TeacherParentEvent(TeacherParentEvent.TYPE_SHOW_ENGLISHBOOK_BOOKS, mBookShelfData.getBsId(), mBookShelfData.getBsNameEn());
                        EventBus.getDefault().post(event);
                        break;
                }
            }
        });

        mIvIcon = (ImageView)mView.findViewById(R.id.iv_bookshelf_icon);
        mTvName = (TextView)mView.findViewById(R.id.tv_bookshelf_name);
        if (mIsZh) {
            mTvName.setText(mBookShelfData.getBsNameZh());
        } else {
            mTvName.setText(mBookShelfData.getBsNameEn());
        }
        mImgBtnMore = (ImageButton)mView.findViewById(R.id.imgbtn_bookshelf_more);

        recyclerView = (RecyclerView)mView.findViewById(R.id.rv_bookrack);



        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);

        bookCoverAdapter = new TpBookCoverAdapter(mContext, mIsZh, mBookShelfData.getBooksList());
        recyclerView.setAdapter(bookCoverAdapter);

    }

    private void loadData() {

    }

    public View getView() {
        return mView;
    }


}
